<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<div id="user_manage_div" style="display: none" class="row">
				<div id="user_manage_div_detail">
					<button id="btn_add_user" type="button" class="btn btn-info" data-toggle="modal" data-target="#btn_add_newuser">新增用户</button>
					<table id="user_manage_div_table" class="table table-hover">
						<thead>
							<tr style="text-align: center;">
								<th style="text-align: center;">序号</th>
								<th style="text-align: center;">用户名</th>
								<th style="text-align: center;">联系方式</th>
								<th style="text-align: center;">地址</th>
								<th style="text-align: center;">用户类型</th>
								<th style="text-align: center;">操作</th>
								<th style="display: none">id</th>
							</tr>
						</thead>
						<tbody id="user_manage_div_table_tbody">
							
						</tbody>
					</table>
				</div>
			</div>
					<!-- 新增用户Modal -->
	<div class="modal fade" id="btn_add_newuser" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="change_title">新增用户</h4>
				</div>
				<form id="btn_add_newuser_form">
					<div class="modal-body" id="change_div">
						<div id="change_div_1" class="input-group">
							<span class="input-group-addon">用户名:</span> <input type="text"
								class="form-control" placeholder="请输入用户名"
								aria-describedby="basic-addon1" required="required"
								name="user_username">
						</div>
						<div id="change_div_2" class="input-group">
							<span class="input-group-addon">密码:&nbsp;&nbsp;&nbsp;</span> <input
								type="text" class="form-control" placeholder="请输入密码"
								aria-describedby="basic-addon1" required="required"
								name="user_password">
						</div>
						<div id="change_div_3" class="input-group">
							<span class="input-group-addon">联系方式</span> <input type="text"
								class="form-control" placeholder="请输入手机号码"
								aria-describedby="basic-addon1" required="required" name="tel" >
						</div>
						<div id="change_div_4" class="input-group">
							<span class="input-group-addon">通讯地址</span> <input type="text"
								class="form-control" placeholder="请输入联系地址"
								aria-describedby="basic-addon1" required="required"
								name="address">
						</div>
						<div id="change_div_4" class="input-group">
							<span class="input-group-addon">用户类型</span>
							<select class="form-control">
								<option value="1">普通用户</option>
								<option value="0">管理员</option>
							</select>
						</div>
						<div id="msg2">
							<span class="msg2_span1"></span>
							<span class="msg2_span2"></span>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="submit" class="btn btn-primary">添加</button>
					</div>
				</form>
			</div>
		</div>
		</div>
				<!-- btn修改用户Modal -->
	<div class="modal fade" id="btn_change_user" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="change_title">修改用户</h4>
				</div>
				<form id="btn_change_user_form">
					<div class="modal-body" id="change_div">
						<div id="btn_change_user_div_1" class="input-group">
							<span class="input-group-addon">用户名:</span> <input type="text"
								class="form-control" placeholder="请输入用户名"
								aria-describedby="basic-addon1"
								name="user_username" disabled="disabled">
						</div>
						<div id="btn_change_user_div_2" class="input-group">
							<span class="input-group-addon">密码:&nbsp;&nbsp;&nbsp;</span> <input
								type="text" class="form-control" placeholder="请输入密码"
								aria-describedby="basic-addon1"
								name="user_password">
						</div>
						<div id="btn_change_user_div_3" class="input-group">
							<span class="input-group-addon">联系方式</span> <input type="text"
								class="form-control" placeholder="请输入手机号码"
								aria-describedby="basic-addon1" name="tel" >
						</div>
						<div id="btn_change_user_div_4" class="input-group">
							<span class="input-group-addon">通讯地址</span> <input type="text"
								class="form-control" placeholder="请输入联系地址"
								aria-describedby="basic-addon1"
								name="address">
						</div>
						<div id="btn_change_user_div_5" class="input-group">
							<span class="input-group-addon">用户类型</span>
							<select class="form-control">
								<option value="1">普通用户</option>
								<option value="0">管理员</option>
							</select>
						</div>
						<div id="btn_change_user_div_6" class="input-group" style="display: none">
							<span class="input-group-addon">用户id</span> <input type="text"
								class="form-control"aria-describedby="basic-addon1"
								name="id" disabled="disabled">
						</div>
						<div id="msg2">
							<span class="msg2_span1"></span>
							<span class="msg2_span2"></span>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="submit" class="btn btn-primary">修改</button>
					</div>
				</form>
			</div>
		</div>
		</div>
</body>
<script type="text/javascript">
function btnDeleteUser(obj){
	var id = $(obj).parent().parent().children("td:eq(6)").html();
	$.ajax({
		url : "btn_delete_user", //请求的url地址
		contentType : "application/json; charset=utf-8",
		dataType : "json", //返回格式为json
		type : "POST", //请求方式
		data : JSON.stringify({
			'id':id
		}),
		beforeSend : function() {
		},
		success : function(data) {
			if (data.isSuccess) {
				userManage();
			} else {
				alert("删除失败...");
			}
		},
		complete : function() {
			//请求完成的处理
			//alert("请求完成");
		},
		error : function(req) {
			alert("  error  请联系开发人员 ！");
		}
	});
}
$("#btn_change_user_form").submit(function() {
	$(".msg2_span1").html("");
	$(".msg2_span2").html("");
	$.ajax({
		url : "change_mima", //请求的url地址
		contentType : "application/json; charset=utf-8",
		dataType : "json", //返回格式为json
		type : "POST", //请求方式
		data : JSON.stringify({
			'userName' : $(
					"#btn_change_user_form input[ name='user_username' ] ")
					.val(),
			'passWord' : $(
					"#btn_change_user_form input[ name='user_password' ] ")
					.val(),
			'tel' : $("#btn_change_user_form input[ name='tel' ] ").val(),
			'address' : $("#btn_change_user_form input[ name='address' ] ")
					.val(),
			'userType':$("#btn_change_user_form select").val(),
			'id':$("#btn_change_user_form input[ name='id' ] ").val()
		}),
		beforeSend : function() {
		},
		success : function(data) {
			if (data.isSuccess) {
				$(".msg2_span1").html("修改成功...");
				$("#btn_change_user").modal('hide');
				userManage();
			} else {
				$(".msg2_span1").html("修改失败...");
			}
		},
		complete : function() {
			//请求完成的处理
			//alert("请求完成");
		},
		error : function(req) {
			alert("  error  请联系开发人员 ！");
		}
	});
	return false;
});
$("#btn_add_newuser_form").submit(function() {
	$(".msg2_span1").html("");
	$(".msg2_span2").html("");
	$.ajax({
		url : "user_register", //请求的url地址
		contentType : "application/json; charset=utf-8",
		dataType : "json", //返回格式为json
		type : "POST", //请求方式
		data : JSON.stringify({
			'userName' : $(
					"#btn_add_newuser_form input[ name='user_username' ] ")
					.val(),
			'passWord' : $(
					"#btn_add_newuser_form input[ name='user_password' ] ")
					.val(),
			'tel' : $("#btn_add_newuser_form input[ name='tel' ] ").val(),
			'address' : $("#btn_add_newuser_form input[ name='address' ] ")
					.val(),
			'userType':$("#btn_add_newuser_form select").val()
		}),
		beforeSend : function() {
		},
		success : function(data) {
			if (data.isSuccess) {
				$(".msg2_span1").html("新增成功...");
				$("#btn_add_newuser").modal('hide');
				userManage();
			} else {
				$(".msg2_span1").html("该用户名已经存在...");
			}
		},
		complete : function() {
			//请求完成的处理
			//alert("请求完成");
		},
		error : function(req) {
			alert("  error  请联系开发人员 ！");
		}
	});
	return false;
});
function btnChangeUser(obj){
	$("#btn_change_user_div_1 input").val($(obj).parent().parent().children("td:eq(1)").html());
	$("#btn_change_user_div_3 input").val($(obj).parent().parent().children("td:eq(2)").html());
	$("#btn_change_user_div_4 input").val($(obj).parent().parent().children("td:eq(3)").html());
	if($(obj).parent().parent().children("td:eq(4)").html() == "普通用户"){
		$("#btn_change_user_div_5 select").val(1);
	}else{
		$("#btn_change_user_div_5 select").val(0);
	}
	$("#btn_change_user_div_6 input").val($(obj).parent().parent().children("td:eq(6)").html());
}
</script>
</html>